package com.lizhenhua.fmmall.controller;

import com.lizhenhua.fmmall.service.serviceImpl.ProductCommentsVoListImpl;
import com.lizhenhua.fmmall.service.serviceImpl.ProductServiceImpl;
import com.lizhenhua.fmmall.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "商品信息相关的接口", tags = "商品管理")
@RequestMapping("/product")
@CrossOrigin // 跨域访问请求
public class ProductController {


    @Autowired
    private ProductServiceImpl productService;
    @Autowired
    private ProductCommentsVoListImpl commentsVoList;

    @GetMapping("/detail-info/{productId}")
    @ApiOperation("商品详情信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "productId", value = "商品id", required = true, defaultValue = "3")
    })
    public ResultVo getProductDetail(@PathVariable("productId") String productId) {

        ResultVo productBasicInfo = productService.getProductBasicInfo(productId);

        return productBasicInfo;
    }


    @GetMapping("/detail-params/{productId}")
    @ApiOperation("商品详参数信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "productId", value = "商品id", required = true, defaultValue = "3")
    })
    public ResultVo getProductDetailParams(@PathVariable("productId") String productId) {

        ResultVo productBasicInfo = productService.getProductById(productId);

        return productBasicInfo;
    }


    @GetMapping("/detail-comments/{productId}")
    @ApiOperation("商品评论信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "productId", value = "商品id", required = true, defaultValue = "3")
    })
    public ResultVo getProductComments(@PathVariable("productId") String productId) {

        // 商品评论
        ResultVo productBasicInfo = commentsVoList.productCommentsVoList(productId);

        return productBasicInfo;
    }


    @GetMapping("/detail-commentsPageHelper/{productId}")
    @ApiOperation("分页商品评论信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "productId", value = "商品id", required = true, defaultValue = "3"),
            @ApiImplicitParam(dataType = "int", name = "pageNum", value = "页码数", required = true, defaultValue = "1"),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每页显示几条", required = true, defaultValue = "5")


    })
    public ResultVo selectPageHelperCommentsByProduct(@PathVariable("productId") String productId,
                                                      int pageNum,
                                                      int limit) {

        // 商品评论
        ResultVo pageHelperCommentsList = commentsVoList.selectPageHelperCommentsByProduct(productId, pageNum, limit);

        return pageHelperCommentsList;
    }


    @GetMapping("/detail-commentsPercent/{productId}")
    @ApiOperation("商品评论好评信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "productId", value = "商品id", required = true, defaultValue = "3"),
    })
    public ResultVo selectCommentsPercent(@PathVariable("productId") String productId) {

        // 商品评论
        ResultVo countByProductId = commentsVoList.getCountByProductId(productId);
        return countByProductId;
    }


    @GetMapping("/detail-productBycategory/{categoryId}")
    @ApiOperation("根据三级商品id获取商品信息-商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "categoryId", value = "三级商品信息id", required = true, defaultValue = "49"),
            @ApiImplicitParam(dataType = "int", name = "pageNum", value = "页码", required = true, defaultValue = "1"),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每页显示几条数据", required = true, defaultValue = "5"),
    })
    public ResultVo getProductMesByCategoryId(@PathVariable("categoryId") int categoryId, int pageNum, int limit) {

        ResultVo products = productService.getProductByCategoryId(categoryId, pageNum, limit);

        return products;
    }


    @ApiOperation("根据三级商品id获取-商品品牌信息-商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "categoryId", value = "三级商品信息id", required = true, defaultValue = "49"),

    })
    @GetMapping("/brand/{categoryId}")
    public ResultVo getBrandList(@PathVariable("categoryId") int categoryId) {

        ResultVo products = productService.brandList(categoryId);

        return products;
    }


    @ApiOperation("根据关键词获取商品信息-商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "keyword", value = "关键词", required = true, defaultValue = "虾条"),
            @ApiImplicitParam(dataType = "int", name = "pageNum", value = "页码", required = true, defaultValue = "1"),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每页显示几条数据", required = true, defaultValue = "5"),
    })

    @GetMapping("/search/{keyword}")
    public ResultVo searchProduct(@PathVariable("keyword") String keyword, int pageNum, int limit) {
        ResultVo resultVo = productService.searchProduct(keyword, pageNum, limit);

        return resultVo;
    }


    @ApiOperation("根据关键词 获取品牌信息-商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "keyword", value = "关键词", required = true, defaultValue = "虾条"),
    })

    @GetMapping("/searchBrand/{keyword}")
    public ResultVo searchBrand(@PathVariable("keyword") String keyword) {
        ResultVo resultVo = productService.searchBrand(keyword);

        return resultVo;
    }



}
